package com.airwallex.strategy.impl;

import com.airwallex.model.ExpParam;
import com.airwallex.strategy.CalculateStrategy;

import java.util.List;
import java.util.Stack;

public class UndoStrategy implements CalculateStrategy {
    @Override
    public void execCalc(Stack<ExpParam> numbers, Stack<List<ExpParam>> logs) {
        //先清空当前状态
        while (!numbers.isEmpty()) {
            numbers.pop();
        }

        //上一步的记录放回
        if (!logs.isEmpty()) {
            //计算后的结果在栈顶
            logs.pop();
            if (!logs.isEmpty()) {
                List<ExpParam> numsLog = logs.peek();
                for (ExpParam num : numsLog) {
                    if (num != null) {
                        numbers.push(num);
                    }
                }
            }
        }
    }
}
